import java.util.Arrays;

/**
 * @author admin
 * 1051. 高度检查器
 * 解题思路：将原数组存放到新数组expected，然后将原数组进行排序，定义一个常量初始值为0，对两个数组的元素进行比较，不同则将常量加1，最后返回常量
 */
public class LeeCode1051 {

    public int heightChecker(int[] heights) {

        int []expected = new int[heights.length];

        int j = 0;
        for (int height : heights) {
            expected[j++] = height;
        }

        Arrays.sort(heights);

        int count = 0;
        for (int i = 0 ; i < heights.length;i++){
            if(heights[i] != expected[i]){
                System.out.println("heights" + heights[i] + "--- expected" + expected[i]);
                count++;
            }
        }
        return count;

    }

    public static void main(String[] args) {
        System.out.println(new LeeCode1051().heightChecker(new int[]{1,1,4,2,1,3}));
//        1 1 1 2 3 4
//        1 1 4 2 1 3
    }
}
